package com.gcalsync.component;

import javax.microedition.lcdui.*;
import com.gcalsync.store.Store;

public class ResetOptionsComponent extends MVCComponent implements Runnable
{
	static final Command CMD_CANCEL = new Command("Cancel", Command.CANCEL, 4);
	static final Command CMD_OK = new Command("OK", Command.OK, 2);
	
    Form form;

	/**
    * Gets the <code>Displayable</code> object to be displayed for
    * this component
    *
    * @returns <code>Displayable</code>
	*/
	public Displayable getDisplayable()
	{
		return form;
	}

	/**
	* Updates the view after it is created
	*/
	protected void updateView() {}

	/**
	* Initializes the model before creating the view
	*/
	protected void initModel() {}

	/**
    * Creates the view
	*/
	protected void createView()
	{
		form = new Form("Reset options");
		form.append("Delete GCalSync record store?");

		form.addCommand(CMD_OK);
		form.addCommand(CMD_CANCEL);
		form.setCommandListener(this);
	}

	/**
    * Processes menu commands
    *
    * @param c command to execute
    * @param d <code>Displayable</code> from which
    *                    <code>command</code> originates
	*/
	public void commandAction(Command c, Displayable d)
	{
		//start deletion thread
		if (c == CMD_OK)
			new Thread(this).start();

		//return to Options screen
		Components.options.showScreen();
	}

	/**
    * Entry point for new thread
	*/
	public void run()
	{
		Store.deleteRecordStore();
	}
}


